<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>主播管理</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="http://cdn.viptool.cn/lib/morris.js/0.4.3/morris.css" rel="stylesheet">
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="../../resource/lib/imageview/css/imageviewer.css" rel="stylesheet"/>
    <script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
    <script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
    <script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
            th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316(123123)}"></script>
    <script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316"
            th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js}"></script>
    <style>
        .user-close-config {
            height: 40px;
            line-height: 40px;
        }

        .user-close-config .control-label {
            margin-left: 20px;
            font-weight: normal !important;
        }

        .user-close-config label.off {
            background-color: red;
            color: #fff;
            margin-right: 10px;
        }

        .user-close-config label.on {
            background-color: #fff;
            color: #674646;
            border: 1px solid #ccc;
            margin-right: 10px;
        }

        .separator {
            margin: 31px 20px 10px 20px;
            border-bottom: 1px solid #ccc;
        }
    </style>
</head>

<body>
<div class="wrapper wrapper-content tooltip-demo">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div th:replace="fragments/live_fragment::roomDetailFg" class="ibox-title"
                     style="vertical-align: bottom;height: 100%;padding-left: 0;">
                    <h5 style="font-size: 18px;">
                        <img src="../../resource/img/p2.jpg" onerror="this.src='../../resource/img/d_head.jpeg'"
                             alt="" style="width:100px;height:100px;"/>
                    </h5>
                    <div style="margin-left: 120px;width: 50%;margin-top: -6px;">
                        <h3>剑南的直播间</h3>
                        <p style="width: 373px;height: 51px;">
                            非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间非常优秀的直播间</p>
                        <p>创建时间：2012-12-12 12:12:12</p>
                    </div>
                    <button type="button" onclick="liveHandler.edit()"
                            style="float: right;margin-top: -45px;margin-right: 10px;"
                            class="btn btn-primary btn-xl m-b-none">房间设置
                    </button>
                </div>
                <div class="tabs-container" style="margin-top: 20px;">
                    <ul class="nav nav-tabs">
                        <li>
                            <a th:href="@{/live/detail/products(roomId=${room.id})}" href="user_detail.html">商品管理</a>
                        </li>
                        <li class="active">
                            <a th:href="@{/live/detail/directors(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">主播管理</a>
                        </li>
                        <li>
                            <a th:href="@{/live/detail/sessions(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">直播记录</a>
                        </li>
                        <li>
                            <a th:href="@{/live/detail/videos(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">直接间视频</a>
                        </li>
                        <li sec:authorize="hasRole('ADMIN')">
                            <a th:href="@{/live/detail/images(roomId=${room.id})}"
                               href="../live/live_detail_images.html">直接间图片</a>
                        </li>
                        <li sec:authorize="hasRole('ADMIN')">
                            <a th:href="@{/live/detail/users(roomId=${room.id})}"
                               href="../user/user_detail_advance_log.html">直接间用户列表</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body">
                                <div>
                                    <div class="form-inline"
                                         style="padding-top: 10px ;padding-bottom: 15px;text-align: right;">
                                        <button type="button" onclick="liveHandler.addModalShow()"
                                                class="btn btn-primary btn-sm m-b-none">添加主播
                                        </button>
                                    </div>
                                    <div class="table-responsive">

                                        <table class="table table-bordered table-hover table-center">
                                            <thead>
                                            <tr>
                                                <th>主播昵称</th>
                                                <th>主播</th>
                                                <th>是否是自己</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr th:each="item:${directors}">
                                                <td th:text="${item.directorName}"></td>
                                                <td>
                                                    <span th:text="${item.userPO.nickName}"></span>
                                                    &nbsp;&nbsp;&nbsp;
                                                    <span th:text="${item.userPO.mobile}"></span>
                                                </td>
                                                <td th:text="${item.owner?'是':'否'}">是</td>
                                                <td>
                                                    <a th:href="|javascript:liveHandler.changeName(${item.id},'${item.directorName}')|"
                                                       href="javascript:liveHandler.changeName(1,'')">修改主播名称</a>
                                                    <th:block th:if="${!item.owner}">
                                                        |
                                                        <a th:href="|javascript:liveHandler.remove(${item.id})|"
                                                           href="javascript:liveHandler.remove(1)">移除</a>
                                                    </th:block>

                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="sel_user_template">
    <div class="form-inline">
        <p class="form-control-static">{{nickname}}/{{mobile}}</p>
        <button onclick="liveHandler.selUser({{userId}},'{{nickname}}','{{mobile}}')"
                type="button"
                class="btn btn-primary btn-xs m-b-none pickUpShow"
                style="margin-left: 20px;">选择
        </button>
    </div>
    <p style="height: 7px;"></p>
</script>

<script type="text/html" id="add_director_template">
    <div class="form-horizontal" style="width: 600px;">
        <div class="form-group">
            <label class="col-sm-2 control-label">选择用户:</label>

            <div class="col-sm-10 form-inline">
                <input style="width: 200px" id="add_search_user" type="text" class="form-control input-sm"
                       placeholder="用户手机/昵称"/>
                <button onclick="liveHandler.searchUser()"
                        type="button"
                        class="btn btn-primary btn-xs m-b-none pickUpShow"
                        style="margin-left: 20px;">搜索
                </button>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">待选用户:</label>

            <div class="col-sm-10" id="pre_search_content">
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">已选用户:</label>

            <div class="col-sm-10 form-inline">
                <input type="hidden" id="add_user_id"/>
                <p class="form-control-static"><span id="add_user_name"></span>/<span id="add_user_mobile"></span></p>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">主播名称:</label>

            <div class="col-sm-10 form-inline">
                <input style="width: 200px" type="text" class="form-control input-sm" id="add_director_name"
                       placeholder="主播名称"/>
            </div>
        </div>
    </div>
</script>


<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>
<script src="../../resource/lib/imageview/js/imageviewer.min.js"
        th:src="@{/resource/lib/imageview/js/imageviewer.min.js}"></script>
<script type="text/javascript" th:inline="javascript">
    const apiUri = /*[[@{/live/detail/directors}]]*/  "";
</script>

<script type="text/javascript">
    var addModal = $("#add_director_template").modal("添加主播", function () {
        liveHandler.addDirector();
    });

    $(function () {

    });

    var liveHandler = {
        addModalShow: function () {
            addModal.show();
        },
        searchUser: function () {
            let userKey = $.trim($("#add_search_user").val());
            if (userKey.length === 0) {
                return;
            }
            hot.ajax(apiUri + "/findUser", {
                userKey: userKey
            }, function (apiResult) {
                $("#pre_search_content").empty();
                if (apiResult.data.length === 0) {
                    $("#pre_search_content").html('<p class="form-control-static">未找到相关用户</p>');
                    return;
                }
                $.each(apiResult.data, function (o, item) {
                    let tempHtml = $("#sel_user_template").html();
                    tempHtml = tempHtml.replace("{{userId}}", item.userId);
                    tempHtml = tempHtml.replace(/{{nickname}}/g, item.nickname);
                    tempHtml = tempHtml.replace(/{{mobile}}/g, item.mobile);
                    $("#pre_search_content").append(tempHtml);
                })
            }, function () {
            }, "post");
        },
        selUser: function (userId, nickname, mobile) {
            $("#add_user_id").val(userId);
            $("#add_user_name").html(nickname);
            $("#add_user_mobile").html(mobile);
            $("#add_director_name").val(nickname);
        },
        addDirector: function () {
            let userId = $("#add_user_id").val();
            let roomId = $("#hdRoomId").val();
            let directorName = $.trim($("#add_director_name").val());

            hot.ajax(apiUri + '/add', {
                userId: userId,
                roomId: roomId,
                directorName: directorName
            }, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("添加成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("添加失败--" + apiResult.resultMsg);
                }
            }, function () {
            }, "post", 300);
        },
        changeName: function (directorId, directorName) {
            layer.prompt({title: '设置主播名称', formType: 0, value: directorName}, function (text, index) {
                hot.ajax(apiUri + "/changeName", {
                    directorId: directorId,
                    directorName: text
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        });
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        },
        remove: function (directorId) {
            hot.confirm("确定移出该主播？", function () {
                hot.ajax(apiUri + '/remove', {
                    directorId: directorId
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        });
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        }
    }
</script>
</body>

</html>